package sword_to_1;

import node.TreeNode;

public class LeeCode_55_2 {
    public static void main(String[] args) {

    }
    private static boolean isBalanced(TreeNode root) {
        boolean[] ans = new boolean[1];
        dfs(root, 0, ans);
        return !ans[0];
    }
    private static int dfs(TreeNode node, int depth, boolean[] ans){
        if (node == null){
            return depth;
        }
        int d1 = dfs(node.left, depth + 1, ans);
        int d2 = dfs(node.right, depth + 1, ans);
        if (Math.abs(d1 - d2) > 1){
            ans[0] = true;
        }
        return Math.max(d1, d2);
    }
}
